
local function add_shop_iocn(art,x,y,w,h)
    local icon = class.button.create(art,x,y,w,h)
    local ani = class.panel.create(art,(1920-icon.w)/2,650,w,h)
    icon.ani = ani
    icon.title = icon:add_text('',-10,icon.h,icon.w+20,20,10,5)
    icon:child_builder {
        parent = icon,
        type = 'model',
        model = [[UI\Feedback\Autocast\UI-ModalButtonOn.mdl]],
        x = 4,
        y = 2,
        scales = {icon.w / 94,icon.h / 70},
        show_flag = true,
    }

    --动画结束显示按钮
    function ani:move_animation_finish()
        ani:hide()
        icon:show()
    end
    
    --点击按钮选择商店
    function icon:on_button_clicked()
        icon:hide()
        if icon.unit then
            jass.ClearSelection()
            jass.SelectUnit(icon.unit.handle, true)
        end
    end

    ani:hide()
    icon:hide()
    return icon
end

local uis = {
    ['奇遇事件'] = add_shop_iocn([[图标\JNL_qtsj.blp]],1430,730,64,64),
    ['神秘商店'] = add_shop_iocn([[图标\JNL_smsd.blp]],1430 + 80,730,64,64),
}


ac.game:event 'UI-刷新动画'(function(_,player,unit)
    local ui1 = uis[unit.name]
    if ui1==nil then
        return 
    end
    if player:is_self()==false then
        return
    end
    local icon1 = ui1.ani
    icon1:set_real_position((1920-icon1.w)/2,650)
    icon1:show()
    ac.wait(500,function()
        icon1:add_ani_tween({ui1.x,ui1.y},1,'线性')
    end)
    ui1:hide()
    ui1.unit = unit
    --ui1.title:set_text(unit:get_name())

    unit:event '单位-被玩家选择'(function(trg,_,pay)
        if pay==player then
            trg:remove()
            if player:is_self() then
                icon1:hide()
                icon1:stop_ani_tween()
                ui1:hide()
            end
        end
    end)
end)
